package net.aiion.weave.impl.ui;

import net.aiion.weave.spi.feeding.FeedMessage;
import net.aiion.weave.spi.injection.annotations.Inject;
import net.aiion.weave.spi.messaging.MessageQueue;
import net.aiion.weave.spi.messaging.annotations.Queue;
import net.aiion.weave.spi.messaging.annotations.Receives;
import net.aiion.weave.spi.naming.annotations.DynamicScoped;
import net.aiion.weave.spi.naming.annotations.Named;
import net.aiion.weave.spi.ui.ValueMessage;


@DynamicScoped
@Named
public class ComponentMessageDispatcher
{
    @Inject
    @Queue("org.weaveframework.ui")
    private MessageQueue messageQueue;

    public ComponentMessageDispatcher() {
    }

    @Receives("org.weaveframework.feeding")
    public void feedAppeared(final FeedMessage aFeedMessage) {
        messageQueue.sendMessage(createComponentMessage(aFeedMessage.getFeed().getName(), aFeedMessage.getFeed()
            .getValue()));
    }

    private ValueMessage createComponentMessage(final String aComponentId, final String aComponentValue) {
        return new ComponentMessageImpl(aComponentId, aComponentValue);
    }
}
